#include <cstdio>
#include <algorithm>
using namespace std;

int num[110];
int book[100000];

int main() {
	int n;
	scanf("%d", &n);
	for (int i=0; i<n; i++) {
		int a;
		scanf("%d", &a);
		num[i] = a;
		while (a != 1) {
			if (book[a] == 0) {
				book[a]++;
				if (a%2) a=(3*a+1)/2;
				else a/=2;
			} else if (book[a] >= 1) {
				book[a]++;
				break;
			} 
		}
	}
	sort(num, num+n);
	bool first = true;
	for (int i=n-1; i>=0; i--) {
		if (book[num[i]] == 1) {
			if (first) first = false;
			else printf(" ");
			printf("%d", num[i]);
		}
	}
	printf("\n");
	return 0;
}
